package com.example.chat.service.impl;

import com.example.chat.model.Employee;
import com.example.chat.model.ro.EmployeeUpdateRO;
import com.example.chat.repository.EmployeeRepository;
import com.example.chat.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;

/**
 * @Description
 * @Date 2022/11/17 17:25
 * @Author pq
 */
@Service
@Slf4j
public class EmployeeServiceImpl implements EmployeeService {

    @Resource
    private EmployeeRepository employeeRepository;


    @Override
    public void updateEmployee(EmployeeUpdateRO ro){
        Employee employee=new Employee();
        try {
            BeanUtils.copyProperties(employee,ro);
            log.info(employee.toString());
            employeeRepository.save(employee);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
}
